package com.wt.admin.service.language.impl;

import com.aizuda.easy.security.code.BasicCode;
import com.wt.admin.code.language.QA2200;
import com.wt.admin.domain.dto.language.QADTO;
import com.wt.admin.domain.entity.language.QAEntity;
import com.wt.admin.domain.vo.language.QAVO;
import com.wt.admin.mapper.language.QAMapper;
import com.wt.admin.service.language.QAService;
import com.wt.admin.util.AssertUtil;
import com.wt.admin.util.PageUtil;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.util.List;

@Service
public class QAServiceImpl implements QAService {

    @Resource
    private QAMapper qaMapper;

    @Override
    public QAVO add(QADTO data) {
        AssertUtil.Str.isEmpty(data.getTitle(), QA2200.CODE_2200);
        AssertUtil.objIsNull(data.getClassificationId(), QA2200.CODE_2201);
        qaMapper.insert(data);
        return null;
    }

    @Override
    public QAVO del(QADTO data) {
        AssertUtil.objIsNull(data.getId(), BasicCode.BASIC_CODE_99998);
        qaMapper.deleteById(data);
        return null;
    }

    @Override
    public QAVO edit(QADTO data) {
        AssertUtil.objIsNull(data.getId(), BasicCode.BASIC_CODE_99998);
        AssertUtil.Str.isEmpty(data.getTitle(), QA2200.CODE_2200);
        AssertUtil.objIsNull(data.getClassificationId(), QA2200.CODE_2201);
        qaMapper.updateById(data);
        return null;
    }

    @Override
    public PageUtil.PageVO<QAVO> list(PageUtil.PageDTO<QADTO> data) {
        return PageUtil.findPage(data, (page) -> qaMapper.list(page, data.getData()));
    }

    @Override
    public List<QAEntity> findByIds(List<Integer> id) {
        return qaMapper.findByIds(id);
    }
}
